<template>
  <div v-if="list.length > 0" class="hot-popular-wrap">
    <div class="scroll-wrap">
      <div
        v-for="(item, index) in list"
        :key="index"
        class="hot-popular-item"
        @click="goProductDetail(item, index)"
      >
        <img v-lazy="imgUrl(item)" alt="" />
        <div class="info">
          <p class="desc">{{ item.productName || '' }}</p>
          <div class="price">
            <span class="unit">¥</span><span>{{ item.price }}</span
            ><span class="linePrice">¥{{ item.tagPrice }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { formatImgUrl, http2https, getUrlParam } from '@/utils/util';

export default {
  name: 'hotPopular',
  props: {
    hotSaleHighPopular: {
      type: Object,
      default: () => {}
    },
    floorName: {
      type: String,
      default: ''
    },
    floorIndex: {
      type: Number,
      default: 0
    },
    resId: {
      type: [Number, String],
      default: ''
    },
    hotSaleId: {
      type: String,
      default: ''
    },
    hotSaleName: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      list: []
    };
  },
  mounted() {
    const { highPopularProductList } = this.hotSaleHighPopular || {};
    this.list = highPopularProductList || [];
  },
  methods: {
    imgUrl(item) {
      let { productPicUrl } = item || {};
      if (productPicUrl) {
        productPicUrl = formatImgUrl(productPicUrl.split(',')[0], 112, 112);
        return http2https(productPicUrl);
      }
      return null;
    },
    goProductDetail(productObj) {
      this.$router.push({
        path: 'productDetail',
        query: {
          productId: productObj.productNo,
          shopId: getUrlParam().shopId,
          activityNo: productObj.activityNo
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.hot-popular-wrap {
  width: 365px;
  height: 148px;
  margin-left: 10px;
  overflow: hidden;
  margin-bottom: 10px;
}
.scroll-wrap {
  overflow-x: auto;
  display: flex;
  height: 158px;
}
.hot-popular-item {
  width: 102px;
  height: 148px;
  border-radius: 7px;
  overflow: hidden;
  margin-right: 6px;
  background-color: #fff;
  flex-shrink: 0;
  img {
    width: 102px;
    height: 102px;
    object-fit: cover;
    display: block;
  }

  .info {
    padding: 6px;
    .desc {
      width: 90px;
      font-size: 12px;
      font-family: PingFangSC-Regular;
      color: rgba(51, 51, 51, 1);
      line-height: 14px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      margin-bottom: 5px;
    }

    .price {
      font-size: 16px;
      font-family: DINAlternate-Bold, DINAlternate;
      font-weight: bold;
      color: #fe1e3d;
      line-height: 14px;
    }
    .unit {
      font-size: 10px;
      margin-right: 2px;
      color: #fe1e3d;
      font-family: DINAlternate-Bold, DINAlternate;
      font-weight: bold;
    }

    .linePrice {
      text-decoration: line-through;
      font-size: 10px;
      font-family: DINAlternate-Bold, DINAlternate;
      font-weight: bold;
      color: #999;
      line-height: 14px;
      margin-left: 1px;
    }
  }
}
</style>
